<extend name="Public/base" />
<block name="select2"></block>
<block name="content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a class="current">{$meta_title}</a>
		</div>
	</div>
	<div class="container-fluid">
		<br>
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-content ">
						<table id="config_table" class="table table-striped">
							<tr>
								<td class="span3">
									<div class="sort_option">
										<select value="" size="8" id="select_sort">
											<volist name="list" id="vo">
												<option class="ids" title="{$vo.title}" value="{$vo.id}">{$vo.title}</option>
											</volist>
										</select>
									</div>
								</td>
								<td id="sort_btn">
									<button class="top btn btn-info" type="button">第 一</button><br>
									<button class="up btn btn-info" type="button">上 移</button><br>
									<button class="down btn btn-info" type="button">下 移</button><br>
									<button class="bottom btn btn-info" type="button">最 后</button><br>
								</td>
							</tr>
							<tr>
								<td colspan=2 >
									<button class="sort_confirm btn submit-btn btn-success" type="button">确 定</button>&nbsp;<button class="btn btn-danger" type="button" onclick="javascript:location.href='{$back_url}'">返 回</button>
									<input type="hidden" name="ids">
								</td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	<script type="text/javascript">
		$(function(){
			sort();
			$(".top").click(function(){
				rest();
				$("option:selected").prependTo("select");
				sort();
			})
			$(".bottom").click(function(){
				rest();
				$("option:selected").appendTo("select");
				sort();
			})
			$(".up").click(function(){
				rest();
				$("option:selected").after($("option:selected").prev());
				sort();
			})
			$(".down").click(function(){
				rest();
				$("option:selected").before($("option:selected").next());
				sort();
			})
			$(".search").click(function(){
				var v = $("input").val();
				$("option:contains("+v+")").attr('selected','selected');
			})
			function sort(){
				$('option').text(function(){return ($(this).index()+1)+'.'+$(this).text()});
			}

			//重置所有option文字。
			function rest(){
				$('option').text(function(){
					return $(this).text().split('.')[1]
				});
			}

			//获取排序并提交
			$('.sort_confirm').click(function(){
				var arr = new Array();
				$('.ids').each(function(){
					arr.push($(this).val());
				});
				$('input[name=ids]').val(arr.join(','));
				$.post(
					$('form').attr('action'),
					{
					'ids' :  arr.join(',')
					},
					function(data){
						if (data.status) {
							tke_alert(data.info,'alert-success');
	                    }else{
	        				tke_alert(data.info,'alert-error');
	                    }
	                    setTimeout(function(){
	                        if (data.status) {
	                        	$('.sort_cancel').click();
	                        }
	                    },1500);
					},
					'json'
				);
			});

			//点击取消按钮
			$('.sort_cancel').click(function(){
				window.location.href = $(this).attr('url');
			});
			
			//select 初始化
			$('#s2id_select_sort').hide()
			$('#select_sort').show();
		})
		//左侧导航高亮
		highlight_subnav("{:U('Menu/index')}");
	</script>
</block>